package cate.game.pvp.pointrace.data;

import cate.game.opponent.Opponent;
import cate.game.role.RoleSnapshot;
import lombok.Data;
import lombok.Getter;
import lombok.ToString;

import java.util.Objects;

@ToString
@Data
public class PointRaceOpponent implements Opponent {
    @Getter
    private long points;

    private RoleSnapshot snapshot;

    private int rid;

    @Override
    public long getPower() {
        return Objects.isNull(snapshot) ? 0L : snapshot.base.power;
    }

    @Override
    public String uid() {
        return Objects.isNull(snapshot) ? null : snapshot.base.uid;
    }

    public static PointRaceOpponent ofCopy(RoleSnapshot snapshot) {
        return ofCopy(snapshot, 0);
    }

    public static PointRaceOpponent ofCopy(RoleSnapshot snapshot, long points) {
        return of(snapshot, points, true);
    }

    public static PointRaceOpponent ofNoCopy(RoleSnapshot snapshot, long points) {
        return of(snapshot, points, false);
    }

    public static PointRaceOpponent of(RoleSnapshot snapshot, long points, boolean copy) {
        PointRaceOpponent opponent = new PointRaceOpponent();
        opponent.setPoints(points);
        opponent.setSnapshot(copy ? snapshot.copy() : snapshot);
        return opponent;
    }

}
